package com.sdut.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdut.material.pojo.Supplier;
import com.sdut.material.mapper.SupplierMapper;
import com.sdut.material.service.ISupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.material.util.JSONResult;
import com.sdut.material.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Yu
 * @since 2022-04-20
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public Supplier selectById(Integer id) {
        return supplierMapper.selectById(id);
    }

    @Override
    public LayUITableResult selectByPage(Long page, Long limit) {
        IPage<Supplier> iPage = new Page<>(page,limit);
        IPage<Supplier> result = supplierMapper.selectPage(iPage,new QueryWrapper<>());
        return LayUITableResult.ok(result.getTotal(),result.getRecords());
    }

    @Override
    public JSONResult insert(Supplier supplier) {
        supplierMapper.insert(supplier);
        return JSONResult.ok("添加成功");
    }

    @Override
    public JSONResult updateSupplier(Supplier supplier) {
        supplierMapper.updateById(supplier);
        return JSONResult.ok("修改成功");
    }

    @Override
    public void deleteById(Integer supplierId) {
        supplierMapper.deleteById(supplierId);
    }
}
